package com.hsteach.enums;

import com.google.common.collect.Lists;
import com.hsteach.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.hsteach.enums.ApplyTypeEnum.BUILDING;
import static com.hsteach.enums.ApplyTypeEnum.MEETING;

/**
 *
 */
@Getter
@AllArgsConstructor
public enum BuildingUseEnum {
    FJYT_1("FJYT_1", "普通教室", Lists.newArrayList(BUILDING)),
    FJYT_2("FJYT_2", "专用教室", Lists.newArrayList(BUILDING)),
    FJYT_3("FJYT_3", "多媒体教室", Lists.newArrayList(BUILDING)),
    FJYT_4("FJYT_4", "语音室", Lists.newArrayList(BUILDING)),
    FJYT_5("FJYT_5", "实验室", Lists.newArrayList(BUILDING)),
    FJYT_6("FJYT_6", "计算机房", Lists.newArrayList(BUILDING)),
    FJYT_7("FJYT_7", "办公室", Lists.newArrayList(BUILDING)),
    FJYT_8("FJYT_8", "活动室", Lists.newArrayList(BUILDING)),
    FJYT_9("FJYT_9", "寝室", Lists.newArrayList(BUILDING)),
    FJYT_10("FJYT_10", "会议室", Lists.newArrayList(BUILDING, MEETING)),
    FJYT_11("FJYT_11", "阅览室", Lists.newArrayList(BUILDING)),
    FJYT_12("FJYT_12", "安保室", Lists.newArrayList(BUILDING)),
    FJYT_13("FJYT_13", "美术教室", Lists.newArrayList(BUILDING)),
    FJYT_14("FJYT_14", "书法教室", Lists.newArrayList(BUILDING)),
    FJYT_15("FJYT_15", "舞蹈教室", Lists.newArrayList(BUILDING)),
    ;

    private String code;
    private String name;
    private List<ApplyTypeEnum> useTo;

    public static boolean match(ApplyTypeEnum typeEnum, String code) {
        BuildingUseEnum buildingUseEnum = Arrays.stream(BuildingUseEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        if (buildingUseEnum == null) {
            throw new ServiceException("不存在的房间类型");
        }
        if (buildingUseEnum.getUseTo().contains(typeEnum)) {
            return true;
        } else {
            return false;
        }
    }

    public static List<BuildingUseEnum> getBuilding() {
        return Arrays.stream(BuildingUseEnum.values()).filter(e -> e.getUseTo().contains(BUILDING)).collect(Collectors.toList());
    }

    public static BuildingUseEnum getByCode(String code) {
        return Arrays.stream(BuildingUseEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }
}
